function model=update_beta (model, data)

%global model;

k_hat=model.k_hat;

for r=1:model.r2
 for j=1:k_hat 
     
     temp      = model.phi_2(:,r,j)'*data.dataw2(r).w;
     temp      = temp/sum(temp);
     ind       = find(temp<model.MINVALUE);
     temp(ind) = model.MINVALUE;
     temp      = temp/sum(temp);
     
     model.beta_2(r,j).beta = temp;
     
 end
end
    
    
end
